﻿import com.dinmax.isolution.*
import com.dinmax.flash.utilities.xml.*;

class ParseXMLArtifact 
{
	
	public static function parse(node:XMLNode):Array {
		
		var response:Array=new Array();
		var nodes:Array=XMLUtils.getNodes(node,"artifact");
		for (var i:Number=0;i<nodes.length;i++) {
			response.push(getDevice(nodes[i]));
		}
		
		return response;
	}
	
	private static function getDevice(node:XMLNode):Device {
		
		var device:Device;

		switch (XMLUtils.getAttribute(node, "type")) {
			case "dimmer":
				device=new LightDimmer();				
			break;
			
			case "rgb":
				device=new LightRGB();
			break;
			
			case "blind":
				device=new Blind();
			break;
			
			case "lock":
				device=new Door();
			break;
			
			default:
				trace("NO CONOZCO EL TIPO");
			break;
		
		}

		device.setId(XMLUtils.getAttribute(node, "id"));
		
		device.setName(XMLUtils.getAttribute(node, "artifactName"));
		
		device.setGroup(XMLUtils.getAttribute(node, "group"));				
		device.setState(XMLUtils.getAttribute(node, "state"));
		return device;
	}
	
	public static function parseChange(node:XMLNode):Array {
		var response:Array=new Array();
		response.push(getDevice(node));
		
		return response;
	}
	
}